using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using HyperLocal.Core;
using HyperLocal.Service;

namespace HyperLocal.MVC.Controllers
{
    public class MessageController : Controller
    {
        //
        // GET: /Message/
        [Authorize]
        public ActionResult Index()
        {
            Repository repo = ConnectionService.getRepository;
            return View(repo.Find<LocalOrbMessage>(x => x.Active));
        }

        //
        // GET: /Message/Details/5
        [Authorize]
        public ActionResult Details(Guid id)
        {
            Repository repo = ConnectionService.getRepository;
            return View(repo.First<LocalOrbMessage>(x => x.LocalOrbMessageId == id));
        }

        //
        // GET: /Message/Create
        [Authorize]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Message/Create
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            Repository repo = ConnectionService.getRepository;
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Message/Edit/5
        [Authorize]
        public ActionResult Edit(Guid id)
        {
            Repository repo = ConnectionService.getRepository;
            return View(repo.First<LocalOrbMessage>(x => x.LocalOrbMessageId == id));
        }

        //
        // POST: /Message/Edit/5
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            Repository repo = ConnectionService.getRepository;
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View(repo.First<LocalOrbMessage>(x => x.LocalOrbMessageId == id));
            }
        }
    }
}
